<template>
  <div class="normal-msg msg-box">
    <div class="avatar">
      <img :src="source.senderIcon" alt="avatar" @click.self="handleBalance" v-default-img="maleImg" />

      <Balance ref="balanceRef" :senderId="source.senderId" :sender="source.sender" />
    </div>

    <div class="content common-content">
      <div class="msg">
        <div class="txt">{{ source.content }}</div>
        <div class="msg-btm" :class="{ hasRemark: source.remark }">
          <div class="remark" v-if="source.remark">{{ source.remark }}</div>
          <Time :t="source.msgTime" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import Time from '../time.vue'
import Balance from '../balance.vue'
import maleImg from '@/assets/img/defaultImg/male.png'

type Props = {
  source: any
}

defineProps<Props>()

const balanceRef = ref()

const handleBalance = () => {
  balanceRef.value?.open?.()
}
</script>

<style lang="less" scoped>
@import url('./common.less');

.content {
  margin-left: 9px;
  padding-left: 8px;
  padding-right: 8px;
  background: rgba(44, 45, 71, 1);
  color: #fff;

  &::before {
    left: 0;
    top: 10px;
    border-right: 8px solid rgba(44, 45, 71, 1);
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    transform: translateX(-100%);
  }

  .msg .txt {
    padding-left: 4px;
    padding-right: 4px;
  }
}

.msg-btm {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  transform: translate(4px, 4px);

  .remark {
    margin-right: 20px;
    line-height: 1;
    font-size: 12px;
    color: rgba(59, 246, 78, 1);
  }

  &.hasRemark {
    margin-top: 6px;
    transform: translate(0);
    justify-content: space-between;
  }
}
</style>
